package day12;

import com.alibaba.fastjson.JSONObject;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class JSOnTest {
    public static void main(String[] args) {
        List<People> list=new ArrayList<>();
        list.add(new People("秋宏开",21,false,"六安"));
        list.add(new People("林超",25,true,"hefei"));
        list.add(new People("周一文",22,false,"合肥"));
        list.add(new People("马聪宝",21,false,"阜阳"));
        //Object =>json string
        String str = JSONObject.toJSONString(list);
        System.out.println(str);
        try {
            FileWriter fileWriter=new FileWriter("people.json");
            fileWriter.write(str);
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
